<?php

/**
 * Controller_student
 */

class Controller_personnel extends MyApp {

	public function __construct()
	{
		parent::__construct();

		$this->model->staff  	 = YOU::loadModel('staff');
		$this->model->class   	 = YOU::loadModel('class');
		$this->model->grade   	 = YOU::loadModel('grade');
		$this->model->department = YOU::loadModel('department');
		$this->model->semester 	 = YOU::loadModel('semester');
		$this->model->position 	 = YOU::loadModel('position');
		$this->model->research 	 = YOU::loadModel('research');
		$this->model->discipline = YOU::loadModel('discipline');
		$this->model->prepare 	 = YOU::loadModel('prepare');
        $this->model->excel    = YOU::loadModel('excel');
	}
    /** 首页 **/
    public function actionIndex()
    {

    }

    /** 人事任命记录列表 **/
    public function actionList ()
    {   
    	
    	// 进入模块的入口
    	$appoint_type   = (int)$this->get->appoint_type;
    	// 老师类别入口
    	$appoint_staff   = (int)$this->get->appoint_staff;
    	
    	//按条件搜索
    	$where = " ";
    	//获取到页面传过来的要搜索的条件
    	$position_id     = (int)$this->get->position_id;
    	$department_id   = (int)$this->get->department_id;
    	$staff_name      =      $this->get->staff_name;
    	$class_id      	 = (int)$this->get->class_id;
    	$grade_id      	 = (int)$this->get->grade_id;
    	$research_id     = (int)$this->get->research_id;
    	$prepare_id      = (int)$this->get->prepare_id;
    	$discipline_id   = (int)$this->get->discipline_id;
    	$position_type   = (int)$this->get->position_type;
    	
    	if (!empty($appoint_type)) {
    		$where .= " AND appoint_type='{$appoint_type}' ";
			$this->tpl->assign("appoint_type", $appoint_type);
    	}
    	if (!empty($prepare_id)) {
    		$where .= " AND prepare_id='{$prepare_id}' ";
			$this->tpl->assign("prepare_id", $prepare_id);
    	}
    	if (!empty($discipline_id)) {
    		$where .= " AND discipline_id='{$discipline_id}' ";
			$this->tpl->assign("discipline_id", $discipline_id);
    	}
    	if (!empty($position_id)) {
    		$where .= " AND position_id='{$position_id}' ";
			$this->tpl->assign("position_id", $position_id);
    	}
    	if (!empty($department_id)) {
    		$where .= " AND department_id='{$department_id}' ";
			$this->tpl->assign("department_id", $department_id);
    	}
    	if (!empty($research_id)) {
    		$where .= " AND research_id='{$research_id}' ";
			$this->tpl->assign("research_id", $research_id);
    	}
    	if (!empty($staff_name)) {
			// 模糊查询老师
    		$staff_data   = $this->db->fetchRow("SELECT `staff_name`,`staff_id` FROM `tbl_staff` WHERE staff_name LIKE '%{$staff_name}%' ");		
    		$where .= " AND staff_id = {$staff_data['staff_id']} ";
			$this->tpl->assign("staff_name", $staff_name);
    	}
    	if (!empty($grade_id)) {
    		$where .= " AND grade_id='{$grade_id}' ";
    		$this->tpl->assign("grade_id", $grade_id);
    	}
    	if (!empty($class_id)) {
    		$where .= " AND class_id='{$class_id}' ";
    		$this->tpl->assign("class_id", $class_id);
    	}
    	if (!empty($position_type)) {
    		$where .= " AND position_type='{$position_type}' ";
			$this->tpl->assign("position_type", $position_type);
    	}	
        // 分页     
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_appoint` WHERE appoint_staff ='{$appoint_staff}' {$where}");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);

        // 当前页                  
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }
        
		// 列表内容
        $appoint_lists = $this->db->fetchAll("SELECT * FROM `tbl_appoint` WHERE appoint_staff ='{$appoint_staff}' {$where}  ORDER BY appoint_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
  		foreach ($appoint_lists as $key => $value){
  			if($appoint_type ==1){
  			// 部门
  			$department_data = $this->model->department->getInfo($value['department_id']);
  			$appoint_lists[$key]['department_name']=$department_data['department_name'];
  			}
  			if($appoint_type ==2){
  			// 教研組
  			$research_data = $this->model->research->getInfo($value['research_id']);
  			$appoint_lists[$key]['research_name']=$research_data['research_name'];
  			}
  			if($appoint_type ==5){
  			// 备课組
  			$prepare_data = $this->model->prepare->getInfo($value['prepare_id']);
  			$appoint_lists[$key]['prepare_name']=$prepare_data['prepare_name'];
  			}
  			if($appoint_type ==6){
  			// 学科組
  			$discipline_data = $this->model->discipline->getInfo($value['discipline_id']);
  			$appoint_lists[$key]['discipline_name']=$discipline_data['discipline_name'];
  			}
  			if($appoint_type ==4 ||$appoint_type ==3){
  			// 年级
  			$grade_lists = $this->model->grade->getInfo($value['grade_id']);
  			$appoint_lists[$key]['grade_name']=$grade_lists['grade_name'];
  			// 班级
  			$class_lists = $this->model->class->getInfo($value['class_id']);
  			$appoint_lists[$key]['class_name']=$class_lists['class_name'];			
  			}
  			// 职务
  			$position_data = $this->model->position->getInfo($value['position_id']);
  			$appoint_lists[$key]['position_name']=$position_data['position_name'];
  			// 教师名称
  			$staff_data = $this->model->staff->getInfo($value['staff_id']);
  			$appoint_lists[$key]['staff_name']=$staff_data['staff_name'];
  			// 班主任，组长，级长分化
  			$appoint_lists[$key]['position_type'] = $this->position_type[$value['position_type']];
  	
  		}
  		// 全部职位
  		$position_lists = $this->model->position->getAll();
  		// 部门任命列表
  		if($appoint_type ==1){
  		$department_lists = $this->model->department->getAll();
  		}
  		// 教研组任命列表
  		if($appoint_type ==2){	
  		$research_lists = $this->model->research->getAll();
  		}
  		// 班主任任命列表
  		if($appoint_type ==4 ||$appoint_type ==3){
  		$grade_lists = $this->model->grade->getAll(); 		
  		$class_lists = $this->model->class->getAll();
  		}
  		// 备课组任命列表
  		if($appoint_type ==5){	
  		$prepare_lists = $this->model->prepare->getAll();
  		}
  		// 学科组任命列表
  		if($appoint_type ==6){	
  		$discipline_lists = $this->model->discipline->getAll();
  		
  		}
  		
        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";
       
	    $this->tpl->assign("page", $page->show(4, "yahoo"));
		$this->tpl->assign("appoint_lists", $appoint_lists);
		$this->tpl->assign("department_lists", $department_lists);
		$this->tpl->assign("position_lists", $position_lists);
		
		$this->tpl->assign("appoint_type", $appoint_type);
		$this->tpl->assign("grade_lists", $grade_lists);
		$this->tpl->assign("class_id", $class_lists);
		$this->tpl->assign("research_lists", $research_lists);
		
		$this->tpl->assign("prepare_lists", $prepare_lists);
		$this->tpl->assign("discipline_lists", $discipline_lists);
		$this->tpl->assign("appoint_staff", $appoint_staff);
		// 进入模块的位置	
		if ($appoint_type == 1) {
			$this->tpl->display("personnel/m.personnel.one.list.tpl.php");
		}elseif ($appoint_type == 2){
			$this->tpl->display("personnel/m.personnel.two.list.tpl.php");
		}elseif ($appoint_type == 3){
			$this->tpl->display("personnel/m.personnel.three.list.tpl.php");
		}elseif($appoint_type == 4){
			$this->tpl->display("personnel/m.personnel.four.list.tpl.php");
		}elseif($appoint_type == 5){
			$this->tpl->display("personnel/m.personnel.five.list.tpl.php");
		}elseif($appoint_type == 6){
			$this->tpl->display("personnel/m.personnel.six.list.tpl.php");
		}
    	
    }
    public function actionOut(){

        // 进入模块的入口
        $appoint_type   = (int)$this->get->appoint_type;
        // 老师类别入口
        $appoint_staff   = (int)$this->get->appoint_staff;

        //按条件搜索
        $where = " ";
        //获取到页面传过来的要搜索的条件
        $position_id     = (int)$this->get->position_id;
        $department_id   = (int)$this->get->department_id;
        $staff_name      =      $this->get->staff_name;
        $class_id      	 = (int)$this->get->class_id;
        $grade_id      	 = (int)$this->get->grade_id;
        $research_id     = (int)$this->get->research_id;
        $prepare_id      = (int)$this->get->prepare_id;
        $discipline_id   = (int)$this->get->discipline_id;
        $position_type   = (int)$this->get->position_type;

        if (!empty($appoint_type)) {
            $where .= " AND appoint_type='{$appoint_type}' ";
            $this->tpl->assign("appoint_type", $appoint_type);
        }
        if (!empty($prepare_id)) {
            $where .= " AND appoint_type='{$prepare_id}' ";
            $this->tpl->assign("prepare_id", $prepare_id);
        }
        if (!empty($discipline_id)) {
            $where .= " AND appoint_type='{$discipline_id}' ";
            $this->tpl->assign("discipline_id", $discipline_id);
        }
        if (!empty($position_id)) {
            $where .= " AND position_id='{$position_id}' ";
            $this->tpl->assign("position_id", $position_id);
        }
        if (!empty($department_id)) {
            $where .= " AND department_id='{$department_id}' ";
            $this->tpl->assign("department_id", $department_id);
        }
        if (!empty($research_id)) {
            $where .= " AND research_id='{$research_id}' ";
            $this->tpl->assign("research_id", $research_id);
        }
        if (!empty($staff_name)) {
            // 模糊查询老师
            $staff_data   = $this->db->fetchRow("SELECT `staff_name`,`staff_id` FROM `tbl_staff` WHERE staff_name LIKE '%{$staff_name}%' ");
            $where .= " AND staff_id = {$staff_data['staff_id']} ";
            $this->tpl->assign("staff_name", $staff_name);
        }
        if (!empty($grade_id)) {
            $where .= " AND grade_id='{$grade_id}' ";
            $this->tpl->assign("grade_id", $grade_id);
        }
        if (!empty($class_id)) {
            $where .= " AND class_id='{$class_id}' ";
            $this->tpl->assign("class_id", $class_id);
        }
        if (!empty($position_type)) {
            $where .= " AND position_type='{$position_type}' ";
            $this->tpl->assign("position_type", $position_type);
        }
        // 分页
        YOU::loadLib('page', "", '0');
        $tmp = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_appoint` WHERE appoint_staff ='{$appoint_staff}' {$where}");
        $count = $tmp['count'];
        $page_total = ceil($count/PAGE_LIMIT);

        // 当前页
        $p = intval($_GET['p']);
        if ($p == 0){
            $p  = 1;
        }
        if ($p > 1){
            $start = PAGE_LIMIT * ($p-1);
        }else{
            $start = 0;
        }

        // 列表内容
        $appoint_lists = $this->db->fetchAll("SELECT * FROM `tbl_appoint` WHERE appoint_staff ='{$appoint_staff}' {$where}  ORDER BY appoint_id DESC LIMIT {$start}, ".PAGE_LIMIT."");
        foreach ($appoint_lists as $key => $value){
            if($appoint_type ==1){
                // 部门
                $department_data = $this->model->department->getInfo($value['department_id']);
                $appoint_lists[$key]['department_name']=$department_data['department_name'];
            }
            if($appoint_type ==2){
                // 教研組
                $research_data = $this->model->research->getInfo($value['research_id']);
                $appoint_lists[$key]['research_name']=$research_data['research_name'];
            }
            if($appoint_type ==5){
                // 备课組
                $prepare_data = $this->model->prepare->getInfo($value['prepare_id']);
                $appoint_lists[$key]['prepare_name']=$prepare_data['prepare_name'];
            }
            if($appoint_type ==6){
                // 学科組
                $discipline_data = $this->model->discipline->getInfo($value['discipline_id']);
                $appoint_lists[$key]['discipline_name']=$discipline_data['discipline_name'];
            }
            if($appoint_type ==4 ||$appoint_type ==3){
                // 年级
                $grade_lists = $this->model->grade->getInfo($value['grade_id']);
                $appoint_lists[$key]['grade_name']=$grade_lists['grade_name'];
                // 班级
                $class_lists = $this->model->class->getInfo($value['class_id']);
                $appoint_lists[$key]['class_name']=$class_lists['class_name'];
            }
            // 职务
            $position_data = $this->model->position->getInfo($value['position_id']);
            $appoint_lists[$key]['position_name']=$position_data['position_name'];
            // 教师名称
            $staff_data = $this->model->staff->getInfo($value['staff_id']);
            $appoint_lists[$key]['staff_name']=$staff_data['staff_name'];
            // 班主任，组长，级长分化
            $appoint_lists[$key]['position_type'] = $this->position_type[$value['position_type']];

        }
        // 全部职位
        $position_lists = $this->model->position->getAll();
        // 部门任命列表
        if($appoint_type ==1){
            $department_lists = $this->model->department->getAll();
            //var_dump($department_lists);exit;
        }
        // 教研组任命列表
        if($appoint_type ==2){
            $research_lists = $this->model->research->getAll();
            //var_dump($research_lists);exit;
        }
        // 班主任任命列表
        if($appoint_type ==4 ||$appoint_type ==3){
            $grade_lists = $this->model->grade->getAll();
            $class_lists = $this->model->class->getAll();
            //var_dump($grade_lists);var_dump($class_lists);exit;
        }
        // 备课组任命列表
        if($appoint_type ==5){
            $prepare_lists = $this->model->prepare->getAll();

        }
        // 学科组任命列表
        if($appoint_type ==6){
            $discipline_lists = $this->model->discipline->getAll();

        }

        $page = new Page(array('total' => $count, 'perpage' => PAGE_LIMIT));
        $page->next_page   = '下一页>';
        $page->pre_page    = '<上一页';
        $page->style_path  = "static/page_style";

        $this->tpl->assign("page", $page->show(4, "yahoo"));
        $this->tpl->assign("appoint_lists", $appoint_lists);
        $this->tpl->assign("department_lists", $department_lists);
        $this->tpl->assign("position_lists", $position_lists);

        $this->tpl->assign("appoint_type", $appoint_type);
        $this->tpl->assign("grade_lists", $grade_lists);
        $this->tpl->assign("class_id", $class_lists);
        $this->tpl->assign("research_lists", $research_lists);

        $this->tpl->assign("prepare_lists", $prepare_lists);
        $this->tpl->assign("discipline_lists", $discipline_lists);
        $this->tpl->assign("appoint_staff", $appoint_staff);

 
        // 进入模块的位置
        if ($appoint_type == 1) {
            foreach ($appoint_lists as $key => $value){
                $info = array(
                    "0" => $value['department_name'],
                    "1" => $value['position_name'],
                    "2" => $value['staff_name'],
                );
                $data_lists[$key] = $info;
             }
            $this->model->excel->outData("appoint1", $data_lists);
         
            $this->tpl->display("personnel/m.personnel.one.list.tpl.php");
        }elseif ($appoint_type == 2){
            foreach ($appoint_lists as $key => $value){
                $info = array(
                    "0" => $value['research_name'],
                    "1" => $value['position_type'],
                    "2" => $value['staff_name'],
                );
                $data_lists[$key] = $info;
            }
            $this->model->excel->outData("appoint2", $data_lists);
            $this->tpl->display("personnel/m.personnel.two.list.tpl.php");
        }elseif ($appoint_type == 3){
            foreach ($appoint_lists as $key => $value){


                $info = array(
                    "0" => $value['grade_name'],
                    "1" => $value['position_type'],
                    "2" => $value['staff_name'],
                );
                $data_lists[$key] = $info;
            }
            $this->model->excel->outData("appoint3", $data_lists);
            $this->tpl->display("personnel/m.personnel.three.list.tpl.php");
        }elseif($appoint_type == 4){
            foreach ($appoint_lists as $key => $value){

                $info = array(
                    "0" => $value['grade_name'],
                    "1" => $value['class_name'],
                    "2" => $value['position_type'],
                    "3" => $value['staff_name'],
                );
                $data_lists[$key] = $info;
            }
            $this->model->excel->outData("appoint4", $data_lists);
            $this->tpl->display("personnel/m.personnel.four.list.tpl.php");
        }elseif($appoint_type == 5){
            foreach ($appoint_lists as $key => $value){
                $info = array(
                    "0" => $value['prepare_name'],
                    "1" => $value['position_type'],
                    "2" => $value['staff_name'],
                );
                $data_lists[$key] = $info;
            }
            $this->model->excel->outData("appoint5", $data_lists);
            $this->tpl->display("personnel/m.personnel.five.list.tpl.php");
        }elseif($appoint_type == 6){
            foreach ($appoint_lists as $key => $value){
                $info = array(
                    "0" => $value['discipline_name'],
                    "1" => $value['position_type'],
                    "2" => $value['staff_name'],
                );
                $data_lists[$key] = $info;
            }
            $this->model->excel->outData("appoint6", $data_lists);
            $this->tpl->display("personnel/m.personnel.six.list.tpl.php");
        }

    }
	
    /** 人事任命添加 **/
    public function actionAdd()
    {   
    	// 进入模块的入口
    	$appoint_type   = (int)$this->get->appoint_type;
    	// 老师类别入口
    	$appoint_staff   = (int)$this->get->appoint_staff;
    	
    	// 全部职位
  		$position_lists = $this->model->position->getAll();
  		
  		if($appoint_type ==1){
  		// 全部部门
  		$department_lists = $this->model->department->getAll();
  		}
  		if($appoint_type ==2){
  		// 教研組
  		$research_lists = $this->model->research->getAll();
  		}
  		if($appoint_type ==5){
  		// 备课組
  		$prepare_lists = $this->model->prepare->getAll();
  		}
  		if($appoint_type ==6){
  		// 学科組
  		$discipline_lists = $this->model->discipline->getAll();
  		}  		
  		if($appoint_type ==4 ||$appoint_type ==3){
  		// 全部年級
  		$grade_lists = $this->model->grade->getAll();
  		// 全部班級
  		$class_lists = $this->model->class->getAll();
  		}
  		// 全部老師
  		$staff_lists = $this->db->fetchAll("select * from tbl_staff WHERE staff_external = '{$appoint_staff}'");
  				
    	if ($_POST){
    		
    		$position_id     = (int)$this->post->position_id;
    		$department_id   = (int)$this->post->department_id;
    		$staff_name      =      $this->post->staff_name;
    		$staff_id     	 = 		$this->post->staff_id;
    		$class_id      	 = (int)$this->post->class_id;
    		$grade_id      	 = (int)$this->post->grade_id;
    		$research_id     = (int)$this->post->research_id;
    		$prepare_id      = (int)$this->post->prepare_id;
    		$discipline_id   = (int)$this->post->discipline_id;
    		$position_type   = (int)$this->post->position_type;
    		
    		if ($appoint_type == 1) {
    			$position_type = 1;
    		}
    	
            if($appoint_type ==4){
                $cdata = $this->db->fetchRow("select * from `tbl_appoint` WHERE `class_id` = {$class_id} AND appoint_type =4");
                if($cdata)Helper_Client::alert("该班级已有班主任");
            }
            if($appoint_type ==3){
                $gdata = $this->db->fetchRow("select * from `tbl_appoint` WHERE `grade_id` = {$grade_id}  AND appoint_type =3");
                if($gdata)Helper_Client::alert("该级部已有级长");
            }
			
    		// 下拉和手填不能同时存在
    		if (!empty($staff_id) && !empty($staff_name)){
    			Helper_Client::alert("只能选择一项，手动书写或者下拉");
    		}
    		if (!empty($staff_id)){
    			$staff_data = $this->db->fetchRow("SELECT * FROM `tbl_staff` WHERE  staff_id='{$staff_id}' ");  			
    		}elseif(!empty($staff_name)){
    			
    			$staff_data = $this->db->fetchRow("SELECT * FROM `tbl_staff` WHERE  staff_name='{$staff_name}' "); 			
    		}    	   		   		    		
			if (empty($staff_data)){
				Helper_Client::alert("教师信息不存在");
			} 
			//print_R($position_type);
            	 // 写入数据库
	            $info = array(

	            "department_id"      => $department_id,
	            "grade_id"        	 => $grade_id,
	            "class_id"           => $class_id,
	            "position_id"        => $position_id,
	            "class_id"           => $class_id,
	            "research_id"        => $research_id,
	            "staff_id"           => $staff_data['staff_id'],
	            "appoint_type"       => $appoint_type,
	            "type_id"            => $position_id,
	            "discipline_id"      => $discipline_id,
	            "prepare_id"         => $prepare_id,
	            "appoint_staff"      => $appoint_staff,
	            "position_type"      => $position_type,
	            "status"             => 1,
	            "create_time"        => date("Y-m-d H:i:s"),
	            "update_time"        => "0000-00-00 00:00:00",
	                      
	            );
            	$this->db->do_insert("tbl_appoint", $info);
			
           // 跳转
           Helper_Client::location("添加成功", "index.php?a=personnel.list&appoint_type={$appoint_type}&appoint_staff={$appoint_staff}");
        }
 	
        $this->tpl->assign("department_lists", $department_lists);
		$this->tpl->assign("position_lists", $position_lists);		
		$this->tpl->assign("appoint_type", $appoint_type);
		$this->tpl->assign("grade_lists", $grade_lists);
		
		$this->tpl->assign("class_id", $class_lists);
		$this->tpl->assign("research_lists", $research_lists);
		$this->tpl->assign("staff_lists", $staff_lists);
		$this->tpl->assign("prepare_lists", $prepare_lists);
		
		$this->tpl->assign("appoint_staff", $appoint_staff);
		$this->tpl->assign("discipline_lists", $discipline_lists);
		
        // 进入模块的位置	
		if ($appoint_type == 1) {
			$this->tpl->display("personnel/personnel.one.add.tpl.php");
		}elseif($appoint_type == 2){
			$this->tpl->display("personnel/personnel.two.add.tpl.php");
		}elseif($appoint_type == 3){
			$this->tpl->display("personnel/personnel.three.add.tpl.php");
		}elseif($appoint_type == 4){
			$this->tpl->display("personnel/personnel.four.add.tpl.php");
		}elseif($appoint_type == 5){
			$this->tpl->display("personnel/personnel.five.add.tpl.php");
		}elseif($appoint_type == 6){
			$this->tpl->display("personnel/personnel.six.add.tpl.php");
		}
		
    }
    
      /** 人事任命修改 **/
    public function actionUpdate()
    {
        // 进入模块的入口
    	$appoint_type   = (int)$this->get->appoint_type;
        $this->tpl->assign('appoint_type',$appoint_type);
    	// 老师类别入口
    	$appoint_staff   = (int)$this->get->appoint_staff;
    	// 全部职位
  		$position_lists = $this->model->position->getAll();
  		
  		if($appoint_type ==1){
  		// 全部部门
  		$department_lists = $this->model->department->getAll();
  		}
  		if($appoint_type ==2){
  		// 教研組
  		$research_lists = $this->model->research->getAll();
  		}
  		if($appoint_type ==5){
  		// 备课組
  		$prepare_lists = $this->model->prepare->getAll();
  		}
  		if($appoint_type ==6){
  		// 学科組
  		$discipline_lists = $this->model->discipline->getAll();
  		}  		 		
  		if($appoint_type ==4 ||$appoint_type ==3){
  		// 全部年級
  		$grade_lists = $this->model->grade->getAll();
  		// 全部班級
  		$class_lists = $this->model->class->getAll();
  		}
  		//$this->assign('appoint_type',$appoint_type);
  		// 全部老師

        $staff_lists = $this->db->fetchAll("select * from tbl_staff WHERE staff_external = '{$appoint_staff}'");

    	// 获取老师的任职的id并获取信息
    	$appoint_id   		 = (int)$this->get->appoint_id;	
    	$appoint_data = $this->db->fetchRow("SELECT * FROM `tbl_appoint` WHERE  appoint_id='{$appoint_id}' ");	
       
    	if ($_POST){
            $appoint_type    = (int)$this->post->appoint_type;
		    $position_id     = (int)$this->post->position_id;
    		$department_id   = (int)$this->post->department_id;
    		$staff_name      =      $this->post->staff_name;
    		$staff_id     	 = 		$this->post->staff_id;
    		$class_id      	 = (int)$this->post->class_id;
    		$grade_id      	 = (int)$this->post->grade_id;
    		$research_id     = (int)$this->post->research_id;
    		$prepare_id      = (int)$this->post->prepare_id;
    		$discipline_id   = (int)$this->post->discipline_id;
    		$position_type   = (int)$this->post->position_type;
            if($appoint_type == 4){
                $cdata = $this->db->fetchRow("select * from `tbl_appoint` WHERE `class_id` = {$class_id}");
                if($cdata)Helper_Client::alert("该班级已有班主任");
            }elseif($appoint_type == 3){
                //echo 123;
                $gdata = $this->db->fetchRow("select * from `tbl_appoint` WHERE `grade_id` = {$grade_id}");
                if($gdata)Helper_Client::alert("该级部已有级长");
            }
			
    		// 下拉和手填不能同时存在
    		if (!empty($staff_id) && !empty($staff_name)){
    			Helper_Client::alert("只能选择一项，手动书写或者下拉");
    		}
    		if (!empty($staff_id)){
    			$staff_data = $this->db->fetchRow("SELECT * FROM `tbl_staff` WHERE  staff_id='{$staff_id}' ");  			
    		}elseif(!empty($staff_name)){
    			
    			$staff_data = $this->db->fetchRow("SELECT * FROM `tbl_staff` WHERE  staff_name='{$staff_name}' "); 			
    		}   	   		   		    		
			if (empty($staff_data)){
				Helper_Client::alert("教师信息不存在");
			} 
            
    		// 写入数据库
    		$info = array(
    		
    		"department_id"      => $department_id,
    		"grade_id"        	 => $grade_id,
    		"class_id"           => $class_id,
    		"position_id"        => $position_id,
    		"class_id"           => $class_id,
    		"research_id"        => $research_id,
    		"staff_id"           => $staff_data['staff_id'],
    		"appoint_type"       => $appoint_type,
    		"type_id"            => $position_id,
    		"discipline_id"      => $discipline_id,
    		"prepare_id"         => $prepare_id,
    		"appoint_staff"      => $appoint_staff,
    		"position_type"      => $position_type,
    		"status"             => 1,
    		"create_time"        => date("Y-m-d H:i:s"),
    		"update_time"        => "0000-00-00 00:00:00",
    		
    		);
    		$this->db->do_update("tbl_appoint", $info, "appoint_id='{$appoint_id}'");

 if(empty($appoint_type)){$appoint_type=1;}
			 //跳转
             Helper_Client::location("修改成功", "index.php?a=personnel.list&appoint_type={$appoint_type}");
        }
      
        $this->tpl->assign("department_lists", $department_lists);
		$this->tpl->assign("appoint_data", $appoint_data);		
		$this->tpl->assign("appoint_type", $appoint_type);
		$this->tpl->assign("grade_lists", $grade_lists);
		
		$this->tpl->assign("class_id", $class_lists);
		$this->tpl->assign("position_lists", $position_lists);
		$this->tpl->assign("research_lists", $research_lists);
		$this->tpl->assign("staff_lists", $staff_lists);
		
		$this->tpl->assign("prepare_lists", $prepare_lists);		
		$this->tpl->assign("discipline_lists", $discipline_lists);
		$this->tpl->assign("appoint_staff", $appoint_staff);
		
        // 进入模块的位置	
		if ($appoint_type == 1) {
			$this->tpl->display("personnel/personnel.one.update.tpl.php");
		}elseif ($appoint_type == 2){
			$this->tpl->display("personnel/personnel.two.update.tpl.php");
		}elseif ($appoint_type == 3){
			$this->tpl->display("personnel/personnel.three.update.tpl.php");
		}elseif($appoint_type == 4){
			$this->tpl->display("personnel/personnel.four.update.tpl.php");
		}elseif($appoint_type == 5){
			$this->tpl->display("personnel/personnel.five.update.tpl.php");
		}elseif($appoint_type == 6){
			$this->tpl->display("personnel/personnel.six.update.tpl.php");
		}
    }

    /** 人事任命删除 **/
     public function actionDel ()
    {	
    	// 进入模块的入口
    	$appoint_type   = (int)$this->get->appoint_type;
    	// 老师类别入口
    	$appoint_staff   = (int)$this->get->appoint_staff;
    	
        $appoint_id = (int)$this->get->appoint_id;
        $this->db->query("DELETE  FROM `tbl_appoint` WHERE appoint_id='{$appoint_id}'");
        Helper_Client::location("删除成功", "index.php?a=personnel.list&appoint_type={$appoint_type}");
    }

}

?>